clear all
set more off
cd /Users/zimaoxiao/Dropbox/CC_Yield_Predict/replication_package/  // Navigate to replication folder on your own machine

cap mkdir data/figure

qui {
* --------------------------
* Figure 2: baseline 2020

use data/figure/baseline_2020, clear
rename (yield2000 cc2020_lin cc2020_quad trends2020_lin trends2020_quad yield2020) (m1 m2 m3 m4 m5 m6)
reshape long m, i(county_fips) j(row)

gen row_name=""
replace row_name = "(1) Actual Yields in 2000" if row==1
replace row_name = "(2) Predicted Yields in 2020 under CC (linear trends)" if row==2
replace row_name = "(3) Predicted Yields in 2020 under CC (quadratic trends)" if row==3
replace row_name = "(4) Predicted Yields in 2020 under CC + Tech (linear trends)" if row==4
replace row_name = "(5) Predicted Yields in 2020 under CC + Tech (quadratic trends)" if row==5
replace row_name = "(6) Actual Yields in 2020" if row==6

gen color = 1 if inlist(row,1,6)
replace color = 2 if inlist(row,2,3)
replace color = 3 if inlist(row,4,5)

noi export delimited using data/figure/Figure2.csv, replace

* --------------------------
* Figure 3: baseline 2050
use data/figure/baseline_2050, clear
rename (yield2020 cc2050_lin_245 cc2050_quad_245 trends2050_lin_245 trends2050_quad_245 cc2050_lin_585 cc2050_quad_585 trends2050_lin_585 trends2050_quad_585) (m1 m2 m3 m4 m5 m6 m7 m8 m9)
reshape long m, i(county_fips) j(row)

gen row_name=""
replace row_name = "(1) Actual Yields in 2020" if row==1
replace row_name = "(2) Predicted Yields in 2050 under SSP2-4.5 CC (linear trends)" if row==2
replace row_name = "(3) Predicted Yields in 2050 under SSP2-4.5 CC (quadratic trends)" if row==3
replace row_name = "(4) Predicted Yields in 2050 under SSP2-4.5 CC + Tech (linear trends)" if row==4
replace row_name = "(5) Predicted Yields in 2050 under SSP2-4.5 CC + Tech (quadratic trends)" if row==5
replace row_name = "(6) Predicted Yields in 2050 under SSP5-8.5 CC (linear trends)" if row==6
replace row_name = "(7) Predicted Yields in 2050 under SSP5-8.5 CC (quadratic trends)" if row==7
replace row_name = "(8) Predicted Yields in 2050 under SSP5-8.5 CC + Tech (linear trends)" if row==8
replace row_name = "(9) Predicted Yields in 2050 under SSP5-8.5 CC + Tech (quadratic trends)" if row==9

gen color = 1 if inlist(row,1)
replace color = 2 if inlist(row,2,3)
replace color = 3 if inlist(row,4,5)
replace color = 4 if inlist(row,6,7)
replace color = 5 if inlist(row,8,9)

noi export delimited using data/figure/Figure3.csv, replace

}

*** EOF
